#!/bin/bash

######################################################
# file : p2expensesum
#   This script allows the user to search multi line tags
#
# Author : Anil Kainikara (anilkumar911@gmail.com)
#
# This code is licenced under the GPL.
#
######################################################

#set -x

if [[ -z $1 ]]
then
   date=`date +%d/%m/%Y`;
fi

day=`echo $date | cut -d'/' -f1`
month=`echo $date | cut -d'/' -f2`
year=`echo $date | cut -d'/' -f3`

powerdate=`printf "%d/%.2s/%.2s" "$year" "$month" "1"`

p2search -p '\[expense\]' -s $powerdate | grep expense | grep -v "^$" | sed -e's/^.*\[actual=\([0-9]*\)\].*$/\1+/' | paste -s | sed -e 's/+$//' | bc
